package com.zl.credit.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zl.credit.entity.CreditUserMessage;
import com.zl.credit.mapper.CreditUserMessageMapper;
import com.zl.credit.service.CreditUserMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zl.credit.util.RealName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author anonymous
 * @since 2020-07-14
 */
@Service
public class CreditUserMessageServiceImpl extends ServiceImpl<CreditUserMessageMapper, CreditUserMessage> implements CreditUserMessageService {

    @Autowired
    private RealName realName;

    @Autowired
    private CreditUserMessageMapper userMessageMapper;

    @Override
    public String CheckRealName(String cumName, String idCard) {
        //调用实名认证方法根据结果进行判断
        System.out.println("cumName = " + cumName + ", idCard = " + idCard);
        String res = realName.realName(idCard,cumName);
        System.out.println("res:"+res);
        //把结果转成json
        JSONObject jsonObject = JSONObject.parseObject(res);
        //得到data
        String data = jsonObject.getString("data");
        JSONObject jasondata = JSONObject.parseObject(data);
        //通过data得到desc的值
        String desc = jasondata.getString("desc");
        System.out.println("desc:"+desc);
        return desc;
    }

    @Override
    public String getyzm(String phone) {
        return null;
    }

    @Override
    public void addusermessage(CreditUserMessage userMessage) {

        userMessageMapper.insert(userMessage);



    }

    @Override
    public CreditUserMessage getbyid(String cumid) {
        CreditUserMessage userMessage = userMessageMapper.selectById(cumid);
        return userMessage;
    }

    @Override
    public List<CreditUserMessage> selectAllpage(Integer current,Integer size,HashMap<String,Object> map) {
       Page<CreditUserMessage> page=new Page<CreditUserMessage>(current,size);
        QueryWrapper<CreditUserMessage> wrapper = new QueryWrapper<>();
        wrapper.allEq(map);
        IPage<CreditUserMessage> selectPage = userMessageMapper.selectPage(page, wrapper);
        System.out.println("总记录数"+selectPage.getTotal());
        List<CreditUserMessage> result = selectPage.getRecords();
        //page.getPages();总页数

        return result;
    }
}
